<%-- 实体通用布局过滤条件布局jsp页面 --%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/views/common/taglibs.jsp" %>
<!DOCTYPE>
<html>
  <head>
	  <!-- 引入通用js、css文件(xiaogq) -->
	  <meta name="decorator" content="default">
	  <link rel="stylesheet" type="text/css" href="${ctx}/css/common/operation/sys_operation.css"/>
	  <link rel="stylesheet" type="text/css" href="${ctx}/css/common/export/import_choose_file.css"/>
</head>
  
<body>
	 <div class="button_list">
		 <a href="javascript:;" entityId="${entityId}" entityName="${entityName}" onclick="nextStep2(this)">
            <span class="span_button">
                <span><img src="${ctx}/image/common/operation/oper_nextStep.png"></span>
                <span name="buTitle">下一步</span>
            </span>
		 </a>
		 <a href="javascript:;" onclick="javascript:parent.closeTab();">
            <span class="span_button">
                <span><img src="${ctx}/image/common/operation/oper_CANCEL.png"></span>
                <span name="buTitle">取消</span>
            </span>
		 </a>
	 </div>

	 <div class="content-wrap">
		<div class="import-w" style="width:962px;">
			<div class="import-header">选择导入的数据源文件</div>
			<div class="import-con">
				<div class="import-warning">
					<p class="import-txt">1.你可以把excel(*.xls),excel(*.xlsx)格式的文件导入系统 </p>
					<p class="import-txt">2.请确认文件格式,所选文件格式与文件的格式要相符  </p>
					<p class="import-txt">3.一次导入操作目前只支持1000条以内的记录如果大于1000条记录将不会执行导入操作(注如果文件中存在空行则空行以下的数据不被计算在内)</p>
					<p class="import-txt">4.如果需要导入大数据文件，可以将其拆成若干个小文件然后分别导入</p>
				</div>
				<form id="exportform" action="${ctx}/ExportImport/initshowImportFile.do" method="post" enctype="multipart/form-data">
					<input type="hidden" id="entityId" name="entityId" value="${entityId}"/>
					<input type="hidden" id="entityName" name="entityName" value="${entityName}"/>
					<table class="table-base" style="width:90%;margin:0 auto;">
					  <tr>
						<td class="table-label-title" style="width:20%;">指定导入文件的格式：</td>
						<td class="table-label-edit" style="width:80%;">
							<select name="fileType" class="tb-select" onchange="javascript:funChangeExport();">
							   <option value="xls">Excel(*.xls)</option>
							   <option value="xlsx">Exce(*.xlsx)</option>
							   <option value="csv">Exce(*.csv)</option>
							</select>
						</td>
					  </tr>
					  <tr class="format-cvs">
						  <td>&nbsp;</td>
						  <td  align="left">
							  <label for="comma" class="sdialog-option" >
								  <input  type="radio" id="comma" name="commacutup" checked="checked" style="float:left;margin-top:15px;"/>
								  <span style="float:left;height:40px;line-height:40px;" >逗号分隔的文件</span>
							  </label>
						  </td>
					</tr>
					<tr class="format-cvs">
						<td>&nbsp;</td>
					  <td style="text-align: left;" >
						 <label for="commacutup" class="sdialog-option" style="float: left;">
							 <input  type="radio" id="commacutup" name="commacutup" style="float:left;margin-top:15px;" />
							 <span style="float:left;height:40px;line-height:40px;" >自定义分隔符分隔的文件</span>
						 </label>
						 <input type="text" id="punctuate" name="punctuate" value="," class="tb-input" style="width:50px; float:left;margin-top:8px;" />
					  </td>
					</tr>
					<tr class="format-cvs">
						<td class="table-label-title">编码方式：</td>
						<td style="text-align: left;" class="table-label-edit">
							<select id = "importEcord" name="importEcord" class="tb-select" >
								<option value="UTF-8">Unicode (UTF8) 字符编码</option>
								<option value="GBK">GBK 汉字国标扩展码</option>
								<option value="GB2312">GB2312 简体中文字符编码</option>
							</select>
						</td>
					</tr>
					<tr>
						<td class="table-label-title">
						</td>
						<td class="table-label-edit">
							<input name="file" type="file" class="tb-input" accept="application/vnd.ms-excel" />
						</td>
					  </tr>
					</table>
				</form>
			</div>
		</div>
	 </div>

	 <script type="text/javascript">
		 $(document).ready(function(){
			 //改变导入文件格式方法
			 funChangeExport();
		 });

		 //下一步
		 function nextStep2(node){
			 $('#exportform').ajaxForm({
				 beforeSubmit:validateMethod,
				 success:function(data) {
					 data = eval('('+data+')');
					 var hasValue = data.hasValue;
					 if(hasValue <= 0){
						 alert("文件内容不能为空,请重新选择正确格式的文件!");
					 }else if(hasValue > 1001){
						 alert("每次导入的数据不能超过1000条!");
					 }else{
						 var fileType = data.fileType;//文件类型
						 var entityName = data.entityName;//实体中文名称
						 var entityId = data.entityId;//实体id
						 var fileName = data.fileName;//文件名称
						 if(fileType == ".csv"){
							 var url = "ExportImport/resolveImportFileCell.do?entityId="+entityId+"&entityName="+entityName+"&fileName="+fileName;
							 parent.replaceIframe({title:"导入:"+entityName+":映射字段",url:url});
						 }else{
							 var url = "ExportImport/showImportFileTable.do?entityId="+entityId+"&entityName="+entityName+"&fileName="+fileName;
							 parent.replaceIframe({title:"导入:"+entityName+":选择工作表",url:url});
						 }
					 }
				 }
			 });
			 $("#exportform").submit();
		 }

		 function validateMethod(){
			 var fileType = $("select[name='fileType']").val();
			 var path = $("input[name='file']").val();
			 var attr = path.substring(path.lastIndexOf(".")+1);
			 //判断文件选择类型是否相同
			 if(path==''){
				 alert("文件不能为空，请选择文件!");
				 return false;
			 }else{
				 if(attr != fileType){
					 alert("文件类型错误，请重新选择!");
					 return false;
				 }
			 }
		 }

		 //改变导入文件格式方法
		 function funChangeExport(){
			 var exportFileKind = $(".tb-select").val();
			 if(exportFileKind == 'csv'){
				 $(".format-cvs").show();
			 }else {
				 $(".format-cvs").hide();
			 }
		 }
	 </script>

    </body>
</html>
